package com.atung.tool.redis;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

import com.atung.dao.BusSchoolBusPaymentDAO;
import com.atung.model.BusSchoolBusPayment;
import com.atung.tool.Dictionaries;

@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

	@Autowired
	private BusSchoolBusPaymentDAO busSchoolBusPaymentDAO;
    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        //获取过期订单消息
    	String expiredKey = message.toString();
    	String orderRedis=Dictionaries.schoolBusOrderReidKey;

    	//存在拼车订单行为
    	if(expiredKey.contains(orderRedis)){
    		String platformOrderNumber=expiredKey.substring(orderRedis.length(),expiredKey.length());
    		System.out.println(platformOrderNumber);
    		BusSchoolBusPayment busSchoolBusPayment=busSchoolBusPaymentDAO.selectBusSchoolBusPaymentByPlatformOrderNumber(platformOrderNumber);
    		if(Objects.nonNull(busSchoolBusPayment)){
    			BusSchoolBusPayment busSchoolBusPayments=new BusSchoolBusPayment();
        		busSchoolBusPayment.setModificationTime(LocalDateTime.now());
        		busSchoolBusPayment.setOrderStatus(200);
        		busSchoolBusPayment.setIsDelect(1);
        		busSchoolBusPayment.setPlatformOrderNumber(platformOrderNumber);
        		busSchoolBusPaymentDAO.updateBusSchoolBusPayment(busSchoolBusPayments);
    		}
    		
    	}
    	
    	
    }
}
